import { Modal, message } from "antd";
import { ExclamationCircleFilled } from "@ant-design/icons";

export const useConfirm = (deleteApi: Function, onTableData: Function) => {
  const onDelete = (row: object) => {
    Modal.confirm({
      title: "你确定要删除吗?",
      icon: <ExclamationCircleFilled />,
      content: "删除后将无法恢复",
      okText: "确定",
      okType: "danger",
      cancelText: "取消",
      async onOk() {
        const { state, msg } = await deleteApi(row);
        if (state === 200) {
          onTableData();
        } else {
          message.error(msg);
        }
      },
      onCancel() {
        console.log("Cancel");
      },
    });
  };

  return [onDelete];
};
